package com.example.presentshopping.ui.activity

import android.app.Dialog
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.fragment.app.FragmentActivity
import com.example.presentshopping.R
import com.example.presentshopping.config.base.BaseMvpActivity
import com.example.presentshopping.mvp.presenter.PublicPresenter
import com.example.presentshopping.net.http.HttpRequest
import com.example.presentshopping.net.http.HttpURL.Req_applyWithdrawal
import com.example.presentshopping.ui.custom.NoDoubleClickListener
import com.example.presentshopping.ui.dialog.MessageDialog
import com.example.presentshopping.utils.ToastUtil
import kotlinx.android.synthetic.main.activity_payby_alipay.*

class PaybyAlipayActivity : BaseMvpActivity() {

    private var queryInfoPresenter: PublicPresenter? = null

    override val layoutId: Int
        get() = R.layout.activity_payby_alipay

    override fun initView(savedInstanceState: Bundle?) {
        queryInfoPresenter = PublicPresenter(context, false, "")
        queryInfoPresenter?.attachView(this)
        title_main_tv.leftBackImageTv.setOnClickListener { finish() }
        button2.setOnClickListener(onClickListener)

    }

    private var onClickListener: View.OnClickListener = object : NoDoubleClickListener() {
        @Throws(Exception::class)
        override fun onNoDoubleClick(v: View) {
            if (!TextUtils.isEmpty(editTextTextPersonName.text)){

                if(!TextUtils.isEmpty(editTextrsonName.text)){
                    if (!TextUtils.isEmpty(editTexersonName.text)){
                        queryInfoPresenter?.netWorkRequestPost(Req_applyWithdrawal,
                            HttpRequest.applyWithdrawal(
                                editTextTextPersonName.text.toString(),
                                editTextrsonName.text.toString(),editTexersonName.text.toString()))
                    }else{
                        showToast("请输入真实姓名")
                    }

                } else{
                    showToast("请输入提现金额")
                }

            }else{
                showToast("请输入支付宝账号")
            }

        }
    }

    override fun showToast(msg: String?) {
       ToastUtil.showMsg(msg)
    }

    override fun onDestroy() {
        queryInfoPresenter?.detachView()
        super.onDestroy()
    }
    override fun onSuccess(data: String?) {

        setDialog("提现申请提交成功", "确定")
    }

    override fun onFailure(e: Throwable?, code: Int, msg: String?, isNetWorkError: Boolean) {
        setDialog(msg, "确定")
    }


    fun  setDialog(text: String?, Confirm: String?){
        MessageDialog.Builder(context as FragmentActivity?)
            .setTvTitle("")
            .setTitle("")
            .setMessage(text)
            .setConfirm(Confirm)
            .setCancel("取消")
            .setListener(object : MessageDialog.OnListener {
                override fun onConfirm(dialog: Dialog?) {

                }

                override fun onCancel(dialog: Dialog?) {
                    dialog?.dismiss()
                }

            }).show()

    }

}